//
//  SettingViewController.m
//  EaseMob
//
//  Created by wwj on 16/5/27.
//  Copyright © 2016年 wfw. All rights reserved.
//

#import "SettingViewController.h"
#import "LoginViewController.h"
#import "SettingArrowItem.h"
#import "SettingGroup.h"
#import <SVProgressHUD.h>
#import <EMSDK.h>

@interface SettingViewController ()

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isSmallCell = TRUE;
    [self addFirstGroup];
    [self addSecondGroup];
    [self addThreeGroup];
}

- (void)addFirstGroup{
    SettingGroup *group = [[SettingGroup alloc] init];
    SettingArrowItem *item = [SettingArrowItem initWithTitle:@"账号与安全"];
    item.subTitle = @"以保护";
    item.subImage = @"TabBar3Sel";
    group.items = @[item];
    [self.dataArray addObject:group];
}

- (void)addSecondGroup{
    SettingGroup *group = [[SettingGroup alloc] init];
    SettingArrowItem *item = [SettingArrowItem initWithTitle:@"新消息通知"];
    SettingArrowItem *item1 = [SettingArrowItem initWithTitle:@"隐私"];
    SettingArrowItem *item2 = [SettingArrowItem initWithTitle:@"通用"];
    group.items = @[item, item1, item2];
    [self.dataArray addObject:group];
}

- (void)addThreeGroup{
    SettingGroup *group = [[SettingGroup alloc] init];
    SettingArrowItem *item = [SettingArrowItem initWithTitle:@"帮助与反馈"];
    SettingArrowItem *item1 = [SettingArrowItem initWithTitle:@"关于微信"];
    group.items = @[item, item1];
    [self.dataArray addObject:group];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == self.dataArray.count - 1) {
        UIView *view = [[UIView alloc] init];
        view.frame = CGRectMake(0, 0, kScreenW, 64);
        view.backgroundColor = [UIColor clearColor];
        
        UIButton *btn = [[UIButton alloc] init];
        btn.frame = CGRectMake(0, 20, kScreenW, 44);
        [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor whiteColor];
        [btn setTitle:@"退出登录" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(onClickExit) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
        return view;
    }
    return nil;
}

- (void)onClickExit{
   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       EMError *error = [[EMClient sharedClient] logout:YES];
       dispatch_async(dispatch_get_main_queue(), ^{
           if (!error) {
               [UIApplication sharedApplication].keyWindow.rootViewController = [[LoginViewController alloc] init];
           }
       });
   });
}


@end
